<%@page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/jsp/comm_css_include.jsp"%>
<!doctype html>
<html>
<head>
<style type="text/css">
	#tabb {
    border: 1px solid #e7eaec;
    border-left: none;
    border-right: none;
}
</style>

</head>
<body class="gray-bg">
	<div class="container creditbody">
		<div class="iboxtitle">
			<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;业务受理>基本资料登记>客户资料修改</span>
			<a href="javascript:void(0)"></a>
		</div>
		<div class="ibox-content ibox-con">
			<form class="form-horizontal" id="formbtSz">
				<%@include file="/web/system/yw/his_yw_with_history_include.jsp"%>
			</form>
		</div>
		<div class="business-manwife">修改经销商</div>
		<div class="business-padding">
			<table cellpadding="0" cellspacing="0" border="0" class="">
				<tr>
					<td style="width:300px;">
						<input  class="form-control" type="hidden" id="business-cho" name="business-cho" />
		    			<input id="p-business-cho" placeholder="经销商" readonly="readonly"  name="p-business-cho" type="text" class="form-control smalliconcur smallicon"   onclick="businesscho('',false);">
					</td>
					<td>
						<button class="btn-danger-my dpbtn dpbtn_blue" type="button" onclick="changeDealerInfo();">修改</button>		
					</td>
				</tr>
			</table>
		</div>	
		<div id="outerb">
			<ul id="tabb">
				<c:if test="${!empty ywBusinessBuyerItems}">
					<c:forEach items="${ywBusinessBuyerItems}"
						var="ywBusinessBuyerItem">
						<c:if test="${ywBusinessBuyerItem.key == '03' && !empty ywBusinessBuyerItem.value}">
							<li class="currentb">购车人</li>
						</c:if>
						<c:if test="${ywBusinessBuyerItem.key == '01' && !empty ywBusinessBuyerItem.value}">
							<li>共同购车人</li>
						</c:if>
						<c:if test="${ywBusinessBuyerItem.key == '02' && !empty ywBusinessBuyerItem.value}">
							<c:forEach items="${ywBusinessBuyerItem.value }"
								var="ywBusinessBuyer" varStatus="status">
								<c:choose>
									<c:when test="${ywBusinessBuyer.cusNo == DAN_BAO_REN_CUS_NO_1 }">
										<li>担保人一</li>
									</c:when>
									<c:when test="${ywBusinessBuyer.cusNo == DAN_BAO_REN_CUS_NO_2 }">
										<li>担保人二</li>
									</c:when>
									<c:when test="${ywBusinessBuyer.cusNo == DAN_BAO_REN_CUS_NO_3 }">
										<li>担保人三</li>
									</c:when>
									<c:when test="${ywBusinessBuyer.cusNo == DAN_BAO_REN_CUS_NO_4 }">
										<li>担保人四</li>
									</c:when>

								</c:choose>
							</c:forEach>
						</c:if>
					</c:forEach>
				</c:if>
			</ul>
			<div id="contentb">
				<c:if test="${!empty ywBusinessBuyerItems}">
					<c:forEach items="${ywBusinessBuyerItems }"
						var="ywBusinessBuyerItem">
						<c:if test="${ywBusinessBuyerItem.key == '03' && !empty ywBusinessBuyerItem.value}">
							<c:forEach items="${ywBusinessBuyerItem.value }" var="ywBusinessBuyer" varStatus="status">
								<c:if test="${status.count == 1 }">
									<!-- 购车人信息 -->
									<%@include file="/web/system/yw/his_zhujieren_include.jsp"%>
								</c:if>
							</c:forEach>
						</c:if>
						<c:if test="${ywBusinessBuyerItem.key == '01' && !empty ywBusinessBuyerItem.value}">
							<c:forEach items="${ywBusinessBuyerItem.value }" var="ywBusinessBuyer" varStatus="status">
								<c:if test="${status.count == 1 }">
									<!-- 共同购车人信息 -->
									<%@include file="/web/system/yw/his_peiou_include.jsp"%>
								</c:if>
							</c:forEach>
						</c:if>
						<c:if test="${ywBusinessBuyerItem.key == '02' && !empty ywBusinessBuyerItem.value}">
							<c:forEach items="${ywBusinessBuyerItem.value }" var="ywBusinessBuyer" varStatus="status">
								<c:choose>
									<c:when test="${status.count == 1 }">
										<!-- 担保人 -->
										<%@include file="/web/system/yw/his_danbaoren1_include.jsp"%>
									</c:when>
									<c:when test="${status.count == 2 }">
										<!-- 担保人 -->
										<%@include file="/web/system/yw/his_danbaoren2_include.jsp"%>
									</c:when>
									<c:when test="${status.count == 3 }">
										<!-- 担保人 -->
										<%@include file="/web/system/yw/his_danbaoren3_include.jsp"%>
									</c:when>
									<c:when test="${status.count == 4 }">
										<!-- 担保人 -->
										<%@include file="/web/system/yw/his_danbaoren4_include.jsp"%>
									</c:when>
								</c:choose>
							</c:forEach>
						</c:if>
					</c:forEach>
				</c:if>
			</div>
		</div>
	</div>
	<!-- public quote -->
	<%@include file="/jsp/comm_js_include.jsp"%>

	<%@include file="/jsp/comm_js_region_include_choice.jsp"%>
	
	<%@include file="/js/common-dpqc/dpqc-summernote/comm_summernote_include.jsp"%>
	
	<!-- 经销商-->
	<%@include file="/jsp/jxschoice_js_include.jsp"%>
	<!-- layerDate plugin javascript -->
	<script type="text/javascript"
		src="${basePath}/js/plugins/layer/laydate/laydate.js"></script>

	<!-- custom js -->
	<script type="text/javascript"
		src="${basePath}/js/yw/gcr.js?v=${empty cssVersion ? Math.random() : cssVersion }"
		charset="utf-8"></script>

	<!--  描述：js脚本  -->
	<script type="text/javascript">
	//手机号码归属地
		function changephoneNo(obj){
 		var $phoneArea = $(obj).parents("td").siblings(".locationAbout").find("input");
		var phone = obj.value;
		if(!phone || phone == ''){
			return;
		}
		$.dpAjax({
			show:false,
	    	url:'${basePath}/PhoneNumberAddrController/getAddressByPhoneNumber',
 			data:{phoneCode:phone},
 			success: function(datas){
 				  var result = datas.result;
	 			  if(result && result != null){
	 				  var resultLocation = result.showapi_res_body;
					  var city = resultLocation.city;
					  if(city && city != ""){
						  $phoneArea.val(city);
					  }else{
						  $phoneArea.val("");
					  }
	 			  }else{
	 				 $phoneArea.val("");
				  }
              }
      	});
    }
		
		function showPhodata(target){
			var obj = $('#'+target+'_tel1');
		var phoneArea = $(obj).parents("td").siblings(".locationAbout").find("input");
			var phoneAreaVal = phoneArea.val();
		var phone = $('#'+target+'_tel1').val();
		if(phoneAreaVal && phoneAreaVal != ""){
			return;
		}
		if(!phone || phone == ''){
			return;
		}
		$.dpAjax({
			show:false,
	    	url:'${basePath}/PhoneNumberAddrController/getAddressByPhoneNumber',
 			data:{phoneCode:phone},
 			success: function(datas){
 				  var result = datas.result;
	 			  if(result && result != null){
	 				  var resultLocation = result.showapi_res_body;
					  var city = resultLocation.city;
					  if(city && city != ""){
						  phoneArea.val(city);
						  phoneArea.attr("readonly","readonly");
					  }else{
						  phoneArea.removeAttr("readonly","readonly");
					  }
	 			  }else{
	 				 phoneArea.removeAttr("readonly","readonly");
				  }
              }
      	});
		}
	
	/* 省市区默认选择 */
 	var hujilayer,objid,objidPhone;
 	
 	function cityChoice(obj){
 		selectProvincesLayer(null,function(){
 			$selectedProvice = $("#provincechioce").children("li:eq(0)")
 			$selectedProvice.addClass("proactive"); 
 			selectCitiesLayer("110000000000",null, function(){
 				$("#citychioce").children("li:eq(0)").addClass("proactive"); 
	 			selectAreasLayer("110100000000");
	    	});
 		});
 		objid = $(obj).attr("id");
 		 
 		hujilayer = layer.open({
 			type:1,
 			title:"省市选择",
 			area: ['650px', '500px'], //宽高
 			content: $("#areaChoice")
 		});
 	};
 	
 	function areachoiceone(obj){
 		var province = $("#provincechioce").find("li.proactive").text();
 		var city = $("#citychioce").find("li.proactive").text();
 		var area = $(obj).text();
 		if(area =="未知地区"){
 			area =" ";
 		}
 		var text = province + city + area;
 		if(objid=="zhujieren_familyRegister"){
 			$("#zhujieren_familyRegister").val(text);
 		}else if(objid=="zhujieren_area"){
 			$("#zhujieren_area").val(text);
 		}else if(objid=="registrationArea"){
 			$("#registrationArea").val(text);
 		}else if(objid=="peiou_familyRegister"){
 			$("#peiou_familyRegister").val(text);
 		}else if(objid=="peiou_area"){
 			$("#peiou_area").val(text);
 		}else if(objid=="danbaoren1_familyRegister"){
 			$("#danbaoren1_familyRegister").val(text);
 		}else if(objid=="danbaoren1_area"){//担保人1户籍
 			$("#danbaoren1_area").val(text);
 		}else if(objid=="danbaoren2_familyRegister"){
 			$("#danbaoren2_familyRegister").val(text);	
 		}else if(objid=="danbaoren2_area"){
 			$("#danbaoren2_area").val(text);
 		}else if(objid=="danbaoren3_familyRegister"){
 			$("#danbaoren3_familyRegister").val(text);	
 		}else if(objid=="danbaoren3_area"){
 			$("#danbaoren3_area").val(text);
 		}else if(objid=="danbaoren4_familyRegister"){
 			$("#danbaoren4_familyRegister").val(text);	
 		}else if(objid=="danbaoren4_area"){
 			$("#danbaoren4_area").val(text);
 		}	
 		layer.close(hujilayer);
 	} 
 	
 	//手机号码归属地2级
 	function poneCitychoicelayer(obj){
 		/* 省市默认选择 */
 		phoneProvinces(null,function(){
 			phoneCities("110000000000");
    		$("#provincechioceTwo").children("li:eq(0)").addClass("proactive");
	    });
 		
 		objidPhone = $(obj).attr("id");
 		 
 		hujilayer = layer.open({
 			type:1,
 			title:"省市选择",
 			area: ['410px', '500px'], //宽高
 			content: $("#areaChoiceTwo")
 		});
 	}
	
		function poneCitychoice(obj){
			var pooneArea = $(obj).text();
			if(objidPhone=="zhujieren_tel1Area"){
 			$("#zhujieren_tel1Area").val(pooneArea);
 		}else if(objidPhone=="zhujieren_tel2Area"){
 			$("#zhujieren_tel2Area").val(pooneArea);
 		}else if(objidPhone=="peiou_tel1Area"){
 			$("#peiou_tel1Area").val(pooneArea);
 		}else if(objidPhone=="danbaoren1_tel1Area"){
 			$("#danbaoren1_tel1Area").val(pooneArea);
 		}else if(objidPhone=="danbaoren1_tel2Area"){
 			$("#danbaoren1_tel2Area").val(pooneArea);
 		}else if(objidPhone=="danbaoren2_tel1Area"){
 			$("#danbaoren2_tel1Area").val(pooneArea);
 		}else if(objidPhone=="danbaoren2_tel2Area"){
 			$("#danbaoren2_tel2Area").val(pooneArea);
 		}else if(objidPhone=="danbaoren3_tel1Area"){
 			$("#danbaoren3_tel1Area").val(pooneArea);
 		}else if(objidPhone=="danbaoren3_tel2Area"){
 			$("#danbaoren3_tel2Area").val(pooneArea);
 		}else if(objidPhone=="danbaoren4_tel1Area"){
 			$("#danbaoren4_tel1Area").val(pooneArea);
 		}else if(objidPhone=="danbaoren4_tel2Area"){
 			$("#danbaoren4_tel2Area").val(pooneArea);
 		}
			layer.close(hujilayer);
		}
 	
 		//改变在职状态
	 	function changeJobStatus(target){
	 		var status = $('#' + target + '_jobStatus').val();
	 		if(!status || status == '') {
	 			status = '01';
	 			$('#' + target + '_jobStatus').val('01');
	 			$('#' + target + '_jobStatus option[id="01"]').attr('selected', 'selected');
	 		}
	 		if('01' == status) { //在职
		    	$('.' + target +'_job_status_rel_remark').hide();
		    	$('.' + target +'_job_status_rel').show();
	 		} else if('02' == status){ //自由职业
		    	$('.' + target +'_job_status_rel').hide();
		    	$('.' + target +'_job_status_rel_remark').show();
	 		}
	 		
	 		changeAffiliateStatus(target);
	    }
 		
 		function changeAffiliateStatus(target) {
 			var jobStatus = $('#' + target + '_jobStatus').val();
 			if('01' == jobStatus) { //在职
	 			var status = $('#' + target + '_affiliateStatus').val();
	 			if(!status || status == '') {
		 			status = '01';
		 			$('#' + target + '_affiliateStatus').val('01');
		 			$('#' + target + '_affiliateStatus option[id="01"]').attr('selected', 'selected');
		 		}
	 			if('01' == status) { //不挂靠
			    	$('.' + target +'_affiliate_status_rel').hide();
		 		} else if('02' == status){ //挂靠
		 			$('.' + target +'_affiliate_status_rel').show();
		 		}
 			} else if('02' == status){ //自由职业
 				$('.' + target +'_affiliate_status_rel').hide();
 			}
 		}
		
	 	$(document).ready(function () {
	 		 $('#p-business-cho').val($('#dealerName').text());
	 		 $('#business-cho').val($('#dealerId').val());
	 		 
	 		 <c:if test="${!empty ywBusinessBuyerItems}">
		        <c:forEach items="${ywBusinessBuyerItems }" var="ywBusinessBuyerItem">
		        	<c:if test="${ywBusinessBuyerItem.key == '03' && !empty ywBusinessBuyerItem.value}">
		        	   $('#zhujieren_remarks').summernote({
			  	            lang: 'zh-CN',
			  	            toolbar:[
			  					['style', ['bold', 'italic', 'underline', 'clear']],
			  					['color', ['color']]
			  	            ]
			  	        });
		        	   $('#saveZhujieren').click(function(){
			   	        	var validstatus = $("#commentForm").valid();
			   	 		    if(validstatus){
			   	        		saveGcr('zhujieren');
			   	 		    }
				   	 		else{
			        			layer.msg("有验证未通过，请仔细检查！",{icon:7})
			        		}
			   	        });
		        	   
		        	    $('#zhujieren_jobStatus').change(function(){
		        		   changeJobStatus('zhujieren');
			   	        });
		        	    $('#zhujieren_affiliateStatus').change(function(){
		        		   changeAffiliateStatus('zhujieren');
			   	        });
		        	</c:if>
		        	<c:if test="${ywBusinessBuyerItem.key == '01' && !empty ywBusinessBuyerItem.value}">
			        	$('#peiou_remarks').summernote({
				            lang: 'zh-CN',
				            toolbar:[
								['style', ['bold', 'italic', 'underline', 'clear']],
								['color', ['color']]
				            ]
				        });
			        	$('#savePeiou').click(function(){
			   				var validstatus = $("#commentFormb").valid();
			   			    if(validstatus){
			   					saveGcr('peiou');
			   			    }
			   			 	else{
			        			layer.msg("有验证未通过，请仔细检查！",{icon:7})
			        		}
			   	        });
			        	
			        	 $('#peiou_jobStatus').change(function(){
			        		   changeJobStatus('peiou');
				   	      });
			        	 $('#peiou_affiliateStatus').change(function(){
			        		   changeAffiliateStatus('peiou');
				   	      });
		        	</c:if>
		        	<c:if test="${ywBusinessBuyerItem.key == '02' && !empty ywBusinessBuyerItem.value}">
			        	<c:forEach items="${ywBusinessBuyerItem.value }" var="ywBusinessBuyer" varStatus="status">
		        			<c:choose>
			        			<c:when test="${ywBusinessBuyer.cusNo == DAN_BAO_REN_CUS_NO_1 }">
			        			   $('#danbaoren1_remarks').summernote({
			        		            lang: 'zh-CN',
			        		            toolbar:[
			        						['style', ['bold', 'italic', 'underline', 'clear']],
			        						['color', ['color']]
			        		            ]
			        		        });
			        			   $('#saveDanbaoren1').click(function(){
						   				var validstatus = $("#commentForme").valid();
						   			    if(validstatus){
						   					saveGcr('danbaoren1');
						   			    }
						   			 	else{
						        			layer.msg("有验证未通过，请仔细检查！",{icon:7})
						        		}
						   	        });
						        	
						        	 $('#danbaoren1_jobStatus').change(function(){
						        		   changeJobStatus('danbaoren1');
							   	      });
						        	 $('#danbaoren1_affiliateStatus').change(function(){
						        		   changeAffiliateStatus('danbaoren1');
							   	      });
			        			</c:when>
			        			<c:when test="${ywBusinessBuyer.cusNo == DAN_BAO_REN_CUS_NO_2 }">
				        			$('#danbaoren2_remarks').summernote({
			        		            lang: 'zh-CN',
			        		            toolbar:[
			        						['style', ['bold', 'italic', 'underline', 'clear']],
			        						['color', ['color']]
			        		            ]
			        		        });
				        			 $('#saveDanbaoren2').click(function(){
							   				var validstatus = $("#commentFormf").valid();
							   			    if(validstatus){
							   					saveGcr('danbaoren2');
							   			    }
								   			 else{
								        			layer.msg("有验证未通过，请仔细检查！",{icon:7})
								        		}
							   	        });
						        	
						        	 $('#danbaoren2_jobStatus').change(function(){
						        		   changeJobStatus('danbaoren2');
							   	      });
						        	 $('#danbaoren2_affiliateStatus').change(function(){
						        		   changeAffiliateStatus('danbaoren2');
							   	      });
			        			</c:when>
			        			<c:when test="${ywBusinessBuyer.cusNo == DAN_BAO_REN_CUS_NO_3 }">
				        			$('#danbaoren3_remarks').summernote({
			        		            lang: 'zh-CN',
			        		            toolbar:[
			        						['style', ['bold', 'italic', 'underline', 'clear']],
			        						['color', ['color']]
			        		            ]
			        		        });
				        			 $('#saveDanbaoren3').click(function(){
							   				var validstatus = $("#commentFormg").valid();
							   			    if(validstatus){
							   					saveGcr('danbaoren3');
							   			    }
							   			 	else{
							        			layer.msg("有验证未通过，请仔细检查！",{icon:7})
							        		}
							   	        });
						        	
						        	 $('#danbaoren3_jobStatus').change(function(){
						        		   changeJobStatus('danbaoren3');
							   	      });
						        	 $('#danbaoren3_affiliateStatus').change(function(){
						        		   changeAffiliateStatus('danbaoren3');
							   	      });
			        			</c:when>
			        			<c:when test="${ywBusinessBuyer.cusNo == DAN_BAO_REN_CUS_NO_4 }">
				        			$('#danbaoren4_remarks').summernote({
			        		            lang: 'zh-CN',
			        		            toolbar:[
			        						['style', ['bold', 'italic', 'underline', 'clear']],
			        						['color', ['color']]
			        		            ]
			        		        });
				        			 $('#saveDanbaoren4').click(function(){
						   				var validstatus = $("#commentFormh").valid();
						   			    if(validstatus){
						   					saveGcr('danbaoren4');
						   			    }
						   			 	else{
						        			layer.msg("有验证未通过，请仔细检查！",{icon:7})
						        		}
						   	        });
						        	
						        	 $('#danbaoren4_jobStatus').change(function(){
						        		   changeJobStatus('danbaoren4');
							   	      });
						        	 $('#danbaoren4_affiliateStatus').change(function(){
						        		   changeAffiliateStatus('danbaoren4');
							   	      });
			        			</c:when>
		        			</c:choose>
		        		</c:forEach>
		        	</c:if>
		        </c:forEach>
	        </c:if>
	        
	        //内置选项卡
	        var $lib = $('#tabb>li');
	        var $ulb = $('#contentb .ul-style');
	        
	        if($ulb && $ulb.length > 0) {
		        $($ulb[0]).css('display','block');
	        }
	        
	        $lib.click(function(){
		        var $this = $(this);
		        var $t = $this.index();
		        $lib.removeClass();
		        $this.addClass('currentb');
		        $ulb.css('display','none');
		        $ulb.eq($t).css('display','block');
		     });
	        //放事件后，可能需要解绑事件
	        getData();
	    });
	 	
	 	
	    function getData(){
	    	$.dpAjax({
        		show:true,
 	    		url:'${basePath}/HisYwBusinessBuyerController/getMultiById',
     			data:{id: $.getUrlData('id')},
     			success: function(datas){
	     				var result = datas.result;
	     				//购车人信息
	     				 var ywBusinessBuyers = result.ywBusinessBuyers;
	     			     if(ywBusinessBuyers) {
		     				 for(var key in ywBusinessBuyers) {
				     			 var ywBusinessPartBuyers = ywBusinessBuyers[key];
				     			 if(!ywBusinessPartBuyers || ywBusinessPartBuyers.length == 0){
				     				 continue;
				     			 }
		     					 var target = '';
			     				 if(key == '03') {
			     					target = 'zhujieren'; //购车人
				     				showBuer(target, ywBusinessPartBuyers[0]);
			     				 } else if(key == '01') {
			     					target = 'peiou';//共同购车人
			     					showBuer(target, ywBusinessPartBuyers[0]);
			     				 } else if(key == '02'){
			     					target = 'danbaoren';//担保人
			     					showBuers(target, ywBusinessPartBuyers);
			     				 }
		     				 }
     				 	}
 	    		}
	 		});
	    }
	    
	   function saveGcr(target, fn, isAllAction){
		   var zhujieren = $('#zhujieren_idno').val();
			var peiou = $('#peiou_idno').val();
			var danbaoren1 = $('#danbaoren1_idno').val();
			var danbaoren2 = $('#danbaoren2_idno').val();
			var danbaoren3 = $('#danbaoren3_idno').val();
			var danbaoren4 = $('#danbaoren4_idno').val();
			
			var idNos = [];
			if(zhujieren && zhujieren != '') {
				idNos.push(zhujieren.trim());
			}
			if(peiou && peiou != '') {
				idNos.push(peiou.trim());
			}
			if(danbaoren1 && danbaoren1 != '') {
				idNos.push(danbaoren1.trim());
			}
			if(danbaoren2 && danbaoren2 != '') {
				idNos.push(danbaoren2.trim());
			}
			if(danbaoren3 && danbaoren3 != '') {
				idNos.push(danbaoren3.trim());
			}
			if(danbaoren4 && danbaoren4 != '') {
				idNos.push(danbaoren4.trim());
			}
			if(idNos.length > 0) {
				for(var i = 0; i < idNos.length; i++) {
					var thisIdNo = idNos[i];
					for(var j = i + 1; j < idNos.length; j++) {
						var targetIdNo = idNos[j];
						if(thisIdNo == targetIdNo) {
							layer.msg("身份证不能重复", {icon: 5});
							return;
						}
					}
				}
			}
		   target = target || 'zhujieren';
		   var data = {};
		   data.saveHis = true;
		   var id = $('#'+target+'_id').val();
		   if(!id || id == '') {
			   layer.msg("购车人ID丢失，请刷新页面重试", {icon: 5});
			   return;
		   }
		   data.id = id;
		   data.busiId = $("#busiId").val();
	 	   data.cusId = $("#customerId").val();
		   data.name=$('#'+target+'_name').val();
		   data.education=$('#'+target+'_education').val();
		   data.familyRegister=$('#'+target+'_familyRegister').val();
		   data.sex=$('#'+target+'_sex').val();
		   data.idno=$('#'+target+'_idno').val();
		   data.area=$('#'+target+'_area').val();
		   data.tel1=$('#'+target+'_tel1').val();
		   data.tel1Area=$('#'+target+'_tel1Area').val();
		   var jobStatus = $('#'+target+'_jobStatus').val();
		   data.jobStatus=$('#'+target+'_jobStatus').val();
		   data.affiliateStatus=$('#'+target+'_affiliateStatus').val();
		   data.company=$('#'+target+'_company').val();
		   if("01" == jobStatus) {
		   	  data.companyIncome=$('#'+target+'_companyIncome').val();
		   } else if("02" == jobStatus){
			  data.companyIncome=$('#'+target+'_companyIncome_remark').val();
		   }
		   data.companyAddr=$('#'+target+'_companyAddr').val();
		   data.job=$('#'+target+'_job').val();
		   data.monthIncome=$('#'+target+'_monthIncome').val();
		   data.workAge=$('#'+target+'_workAge').val();
		   data.companyTel=$('#'+target+'_companyTel').val();
		   data.remarks=$('#'+target+'_remarks').code();
		   if(target=='zhujieren' || target=='danbaoren1' || target=='danbaoren2' || target=='danbaoren3' || target=='danbaoren4') {
			   data.maritalStatus=$('#'+target+'_maritalStatus').val();
			   data.postcode=$('#'+target+'_postcode').val();
			   data.tel2=$('#'+target+'_tel2').val();
			   data.tel2Area=$('#'+target+'_tel2Area').val();
			   data.nowAddr=$('#'+target+'_nowAddr').val();
			   data.nowTel=$('#'+target+'_nowTel').val();
			   data.familyAddr=$('#'+target+'_familyAddr').val();
			   data.familyTel=$('#'+target+'_familyTel').val();
			   data.contact1=$('#'+target+'_contact1').val();
			   data.contact1Tel1=$('#'+target+'_contact1Tel1').val();
			   data.contact1Tel2=$('#'+target+'_contact1Tel2').val();
			   data.contact1Relation=$('#'+target+'_contact1Relation').val();
			   data.contact2=$('#'+target+'_contact2').val();
			   data.contact2Tel1=$('#'+target+'_contact2Tel1').val();
			   data.contact2Tel2=$('#'+target+'_contact2Tel2').val();
			   data.contact2Relation=$('#'+target+'_contact2Relation').val();
	    	} else if(target=='peiou') {
	    	   data.age=$('#'+target+'_age').val();
	    	}
		   var url = '${basePath}/YwBusinessBuyerController/modify';
		   $.dpAjax({
	    		url:url,
    			data:data,
    			success: function(datas){
    				setTimeout(function(){
	    				location.href='${basePath}/web/system/yw/his_ywBussiness.jsp';
    				},3000);
                }
	    	});
	   }
	   
	   //展示购车人
	   function showBuers(target, ywBusinessPartBuyers) {
		   for(var i = 0; i < ywBusinessPartBuyers.length; i++) {
			   var ywBusinessPartBuyer = ywBusinessPartBuyers[i];
			   var $idnos = $("input[value='"+ywBusinessPartBuyer.idno+"']");
			   if($idnos && $idnos.length == 1) {
				   var idnoDom = $idnos[0];
				   var idNo = $(idnoDom).attr('id');
				   var target = idNo.split('_')[0];
				   if(target) {
				   		showBuer(target, ywBusinessPartBuyer);
				   }
			   }
		   }
	   }
	    
	    //展示购车人
	    function showBuer(target, ywBusinessPartBuyer) {
	    	showBuerData(target, ywBusinessPartBuyer);
	    	if(target=='zhujieren' || target=='danbaoren1' || target=='danbaoren2' || target=='danbaoren3' || target=='danbaoren4') {
	    		if(ywBusinessPartBuyer.maritalStatus && ywBusinessPartBuyer.maritalStatus != '') {
	    			$('#'+target+'_maritalStatus').val(ywBusinessPartBuyer.maritalStatus);
	    		}
	    		$('#'+target+'_postcode').val(ywBusinessPartBuyer.postcode);
	    		$('#'+target+'_tel2').val(ywBusinessPartBuyer.tel2);
	    		$('#'+target+'_tel2Area').val(ywBusinessPartBuyer.tel2Area);
	    		$('#'+target+'_nowAddr').val(ywBusinessPartBuyer.nowAddr);
	    		$('#'+target+'_nowTel').val(ywBusinessPartBuyer.nowTel);
	    		$('#'+target+'_familyAddr').val(ywBusinessPartBuyer.familyAddr);
	    		$('#'+target+'_familyTel').val(ywBusinessPartBuyer.familyTel);
	    		$('#'+target+'_contact1').val(ywBusinessPartBuyer.contact1);
	    		$('#'+target+'_contact1Tel1').val(ywBusinessPartBuyer.contact1Tel1);
	    		$('#'+target+'_contact1Tel2').val(ywBusinessPartBuyer.contact1Tel2);
	    		if(ywBusinessPartBuyer.contact1Relation && ywBusinessPartBuyer.contact1Relation != ''){
	    			$('#'+target+'_contact1Relation').val(ywBusinessPartBuyer.contact1Relation);
	    		}
	    		$('#'+target+'_contact2').val(ywBusinessPartBuyer.contact2);
	    		$('#'+target+'_contact2Tel1').val(ywBusinessPartBuyer.contact2Tel1);
	    		$('#'+target+'_contact2Tel2').val(ywBusinessPartBuyer.contact2Tel2);
	    		if(ywBusinessPartBuyer.contact2Relation && ywBusinessPartBuyer.contact2Relation != '') {
	    			$('#'+target+'_contact2Relation').val(ywBusinessPartBuyer.contact2Relation);
	    		}
	    	} else if(target=='peiou') {
	    		if(ywBusinessPartBuyer.age && ywBusinessPartBuyer.age != '') {
    				$('#'+target+'_age').val(ywBusinessPartBuyer.age);
	    		}
	    	}
	    	
	    	changeJobStatus(target);
	    	changeAffiliateStatus(target);
	    }
	    
	    function showBuerData(target, ywBusinessPartBuyer) {
    		$('#'+target+'_id').val(ywBusinessPartBuyer.replaceId);
    		$('#'+target+'_name').val(ywBusinessPartBuyer.name);
    		if(ywBusinessPartBuyer.education && ywBusinessPartBuyer.education != '') {
    			$('#'+target+'_education').val(ywBusinessPartBuyer.education);
    		}
    		$('#'+target+'_familyRegister').val(ywBusinessPartBuyer.familyRegister);
    		if(ywBusinessPartBuyer.sex && ywBusinessPartBuyer.sex != ''){
    			$('#'+target+'_sex').val(ywBusinessPartBuyer.sex);
    		}
    		$('#'+target+'_idno').val(ywBusinessPartBuyer.idno);
    		$('#'+target+'_area').val(ywBusinessPartBuyer.area);
    		$('#'+target+'_tel1').val(ywBusinessPartBuyer.tel1);
    		showPhodata(target);
    		$('#'+target+'_tel1Area').val(ywBusinessPartBuyer.tel1Area);
    		var jobStatus = ywBusinessPartBuyer.jobStatus;
    		if(jobStatus && jobStatus != '') {
    			$('#' + target + '_jobStatus').val(jobStatus);
    		}
    		if(ywBusinessPartBuyer.affiliateStatus && ywBusinessPartBuyer.affiliateStatus != ''){
    			$('#'+target+'_affiliateStatus').val(ywBusinessPartBuyer.affiliateStatus);
    		}
    		$('#'+target+'_company').val(ywBusinessPartBuyer.company);
    		if("01" == jobStatus) {
	   		   	  $('#'+target+'_companyIncome').val(ywBusinessPartBuyer.companyIncome);
	   		   } else if("02" == jobStatus){
	   			 $('#'+target+'_companyIncome_remark').val(ywBusinessPartBuyer.companyIncome);
	   		   }
    		$('#'+target+'_companyAddr').val(ywBusinessPartBuyer.companyAddr);
    		if(ywBusinessPartBuyer.job && ywBusinessPartBuyer.job != '') {
    			$('#'+target+'_job').val(ywBusinessPartBuyer.job);
    		}
    		$('#'+target+'_monthIncome').val(ywBusinessPartBuyer.monthIncome);
    		if(ywBusinessPartBuyer.workAge && ywBusinessPartBuyer.workAge != '') {
    			$('#'+target+'_workAge').val(ywBusinessPartBuyer.workAge);
    		}
    		$('#'+target+'_companyTel').val(ywBusinessPartBuyer.companyTel);
    		$('#'+target+'_remarks').code(ywBusinessPartBuyer.remarks);
	    }
	    
		function changeDealerInfo(){
			var dealerId = $('#business-cho').val();
			var dealerName = $('#p-business-cho').val();
			if(!dealerId || dealerId == '') {
				layer.msg("请先选择经销商", {icon: 5});
				return;
			}
			var busiId = $('#busiId').val();
			$.dpAjax({
				url:'${basePath}/DealerInfoController/changeDealerInfo',
				data:{busiId:busiId,dealerId:dealerId},
				success:function(datas) {
					var dealerInfo = datas.result;
					$('#dealerId').val(dealerInfo.replaceId);
					$('#dealerLevel').text(dealerInfo.dealerLevelDisplay);
					$('#dealerName').text(dealerInfo.dealerName);
				}
			});
			
		}
</script>
</body>
</html>
